<template>
  <el-dialog :visible.sync="open" @close="close" :title="title" width="800px">
    <el-form ref="elForm" :model="formData" size="small" label-width="100px" label-position="left">
      <el-row :gutter="15">
        <el-col :span="24">
          <el-form-item label="计划标题" prop="planTitle">
            <el-input v-model="formData.name" placeholder="请输入计划标题" :style="{ width: '100%' }"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handleConfirm">{{ isedit ? "保存" : "创建救援计划" }}</el-button>
    </div>
  </el-dialog>
</template>
<script>
import dialogMixin from "@/mixins/dialogMixin";
import { addHandleInfo, updateName } from "@/api/response/handleInfo";
import Cookies from "js-cookie";
import * as Auth from "@/utils/auth";

export default {
  name: "PlanEditDialog",
  mixins: [dialogMixin],
  components: {},
  props: [],
  data() {
    return {
      formData: {
        hdInfoId: 0,
        name: "",
        createUser: 0,
      },
      title: "编辑救援计划",
      isedit: false,
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    add() {
      this.formData = {
        hdInfoId: 0,
        name: "",
      };
      this.formData.createUser = Auth.getUserId();
      this.isedit = false;
      this.open = true;
    },
    edit(data) {
      this.formData = Object.assign({}, data);
      this.isedit = true;
      this.open = true;
    },
    handleConfirm() {
      if (this.isedit) {
        updateName(this.formData).then(res => {
          if (res.code == 200) {
            // 提交成功
            this.$modal.msgSuccess("救援计划修改成功");
            this.$emit("handleOk");
            this.close();
          } else {
            // 提交失败
            this.$modal.msgError("救援计划修改失败");
          }
        });
      } else {
        addHandleInfo(this.formData).then(res => {
          if (res.code == 200) {
            // 提交成功
            this.$modal.msgSuccess("救援计划创建成功");
            this.$emit("handleOk");
            this.close();
          } else {
            // 提交失败
            this.$modal.msgError("救援计划创建失败");
          }
        });
      }
    },
  },
};
</script>
<style></style>
